<?php
use Slince\SmartQQ\Client;
include __DIR__ . '/bootstrap.php';
include 'config.php';
//创建smartQQ客户端
$smartQQ = new Client();

//登录获取授权
$smartQQ->login(LOGIN_QR_IMAGE);
//执行之后你会在[LOGIN_QR_IMAGE]对应的位置发现二维码图片； 获取授权的时候程序会锁住直到二维码确认成功；


$userInfo = $smartQQ->getCredential();
$userInfo = $userInfo->toArray();
$json = json_encode($userInfo);
// $userInfo['uin']
try {
    $db = new PDO($dsn, $username, $password); // also allows an extra parameter of configuration
} catch(PDOException $e) {
    die('Could not connect to the database:<br/>' . $e);
}
$time = time();
$result = $db->prepare('SELECT * FROM `sm_member` WHERE `account` = :account AND `expire_time` > :expire_time ');
$result->bindParam(':account',$userInfo['uin']);
$result->bindParam(':expire_time',$time);
$result->execute();
$info = $result->fetch(PDO::FETCH_ASSOC);

if ($info) {
    # 更新数据

    $result = $db->prepare('UPDATE  `sm_member` SET `array` = :array WHERE `account` = :account');
    $result->bindParam(':array',$json);
    $result->bindParam(':account',$userInfo['uin']);
    $result->execute();

}
